<template>
  <div class="used-car-sale">
    <div class="header">
      <el-button @click="$router.go(-1)" class="back-button">&lt;返回</el-button>
      <h1 class="title">瓜子二手车</h1>
      <el-button @click=ping()>二手车评估</el-button>
    </div>

    <div class="advertisement">
      <h2>特惠活动</h2>
      <p>购车即享超值折扣！</p>
      <p>限时抢购，赶快来选购心仪的二手车！</p>
    </div>

    <div class="marquee-container">
      <div class="marquee">
        <div class="marquee-content">
          <img v-for="(image, index) in images" :key="index" :src="image" class="carousel-image" />
        </div>
      </div>
    </div>

    <div class="car-list">
      <h2>推荐二手车</h2>
      <div v-for="(car, index) in cars" :key="index" class="car-item">
        <img :src="car.image" class="car-image" />
        <div class="car-info">
          <h3>{{ car.name }}</h3>
          <p>价格：{{ car.price }}元</p>
          <p>年份：{{ car.year }}</p>
          <p>里程：{{ car.mileage }}公里</p>
        </div>
      </div>
    </div>
  </div>
</template>

<script setup>
import { reactive } from 'vue';
import router from "@/router";

const ping = () => {
  router.push('/work/ping')
};

const images = reactive([
  'http://localhost:8096/a.jpg',
  'http://localhost:8096/b.jpg',
  'http://localhost:8096/c.jpg',
]);

const cars = reactive([
  {
    name: '丰田卡罗拉',
    price: 98000,
    year: 2018,
    mileage: 30000,
    image: 'http://localhost:8096/1.jpg',
  },
  {
    name: '本田思域',
    price: 120000,
    year: 2019,
    mileage: 25000,
    image: 'http://localhost:8096/2.jpg',
  },
  {
    name: '大众途观',
    price: 150000,
    year: 2020,
    mileage: 15000,
    image: 'http://localhost:8096/3.jpg',
  },
]);
</script>

<style scoped>
.used-car-sale {
  padding: 10px;
}

/* Header styles */
.header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 5px;
  border: 1px solid #ddd;
  border-radius: 20px;
  background-color: #f2f2f2;
  margin-bottom: 5px;
  background-color: #f0f0f9;
}

.back-button {
  background-color: #4CAF50; /* Green button */
  color: white;
}

.title {
  margin-left: 10px;
  font-size: 24px;
  font-weight: bold;
}

/* Marquee styles */
.marquee-container {
  overflow: hidden;
  border: 1px solid #ddd;
  border-radius: 5px;
  height: 100px;
  position: relative;
}

.marquee {
  display: flex;
  animation: marquee 15s linear infinite; /* Adjust duration as needed */
}

.marquee-content {
  display: flex;
}

.carousel-image {
  width: 200px; /* Adjust the image width */
  height: 100%; /* Maintain the height */
  object-fit: cover;
}

/* Keyframes for the marquee effect */
@keyframes marquee {
  0% {
    transform: translateX(100%);
  }
  100% {
    transform: translateX(-100%);
  }
}

.advertisement {
  background-color: #f9c2c2;
  padding: 10px;
  margin: 10px 0;
  border-radius: 5px;
  text-align: center;
}

.car-list {
  margin-top: 20px;
}

.car-item {
  display: flex;
  margin-bottom: 15px;
  border: 1px solid #ddd;
  border-radius: 5px;
  overflow: hidden;
}

.car-image {
  width: 120px;
  height: 80px;
  object-fit: cover;
}

.car-info {
  padding: 10px;
}
</style>
